package com.ddm.controller.vx;

import com.ddm.constant.MessageConstant;
import com.ddm.entity.vxEntity.Exam;
import com.ddm.exception.DataErrorException;
import com.ddm.result.Result;
import com.ddm.service.vxService.ExamService;
import com.ddm.vo.vxVo.ExamVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.HashMap;

@RestController
@RequestMapping("/user/contest")
@Slf4j
public class contestController {

    @Autowired
    ExamService examService;


    /**
     * 获取所有竞赛信息
     */
    @GetMapping
    @ApiOperation("获取所有竞赛信息")
    public Result<List<ExamVO>> getContestInfo(){
        log.info("获取所有竞赛信息");
        return Result.success(examService.getContestInfo());
    }

    /**
     * 获取竞赛详情（包含题目列表）
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("获取竞赛详情")
    public Result<ExamVO> getContestDetail(@PathVariable Long id){
        log.info("获取竞赛详情，竞赛ID: {}", id);
        return Result.success(examService.getExamDetail(id));
    }

    /**
     * 获取竞赛统计信息
     */
    @GetMapping("/statistics/{id}")
    @ApiOperation("获取竞赛统计信息")
    public Result<Map<String, Integer>> getContestStatistics(@PathVariable Long id){
        log.info("获取竞赛统计信息，竞赛ID: {}", id);
        ExamService.ExamStatistics statistics = examService.getExamStatistics(id);
        
        Map<String, Integer> result = new HashMap<>();
        result.put("questionCount", statistics.getQuestionCount());
        result.put("registeredCount", statistics.getRegisteredCount());
        result.put("participatedCount", statistics.getParticipatedCount());
        
        return Result.success(result);
    }

}
